package at.main.android;

import java.io.IOException;

public class Connector {

	public static Connection open(String url) throws IOException {
		url = url.toLowerCase();
		String protocols="socket";
		String host="192.168.1.2";
		String port="43";
		
		int iSpl = url.indexOf("://");
		if(iSpl==-1) return null;
		int iDot = url.lastIndexOf(':');
		
		protocols = url.substring(0, iSpl).trim();
		System.out.println("--- protocols:=["+protocols+"]");
		
		if(protocols.equals("comm")){
			//TODO:
		}else
			
		if(protocols.equals("socket")){
			if(iDot - (iSpl+3) <= 0)
				return null;
			if(iDot+1 >= url.length())
				return null;
			host = url.substring(iSpl+3, iDot);
			port = url.substring(iDot+1).trim();
			System.out.println("Connection >> "+protocols+"://"+host+":"+port);
			return new SocketConnection(host, Integer.parseInt(port));
		}else
			
		if(protocols.equals("udp")){
			//TODO:
		}else
			
		if(protocols.equals("sms")){
			//TODO:
		}else
			
		if(protocols.equals("http")){
			//TODO:
		}
		
		return null;
	}

}
